/*
 * Copyright (c) 2011 Imre Fazekas.
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * Neither the name of the Brillien nor the names of its
 * terms and concepts may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

package com.vii.brillien.core.management.db.couchdbDocument;

import com.vii.brillien.ignition.transport.BrillienCommunication;
import org.jcouchdb.document.BaseDocument;

import java.util.HashMap;

/**
 * CouchDB Document Type to store the starting environment of an indispensable Flow instance
 */
public class IndispensableFlow extends BaseDocument {

    /**
     * Constants for the state flag of the document
     */
    public static final String          FLOW_STARTED    = "Started";
    public static final String          FLOW_FINISHED   = "Finished";
    public static final String          FLOW_FAILED     = "Failed";
    public static final String          FLOW_SUSPENDED  = "Suspended";

    /**
     * Name of the flow
     */
    protected String                    flowName;

    /**
     * State representation of the given flow
     */
    protected HashMap<String, Object>   flowStateSpace;

    /**
     * Execution start time of the flow in millisecs
     */
    protected long                      startDate;

    /**
     * Timout of the flow in millisecs
     */
    protected long                      timeout;

    /**
     * Message containing the error message created by observing flow execution failure
     */
    protected String                    failureMessage;

    /**
     * Status of the flow indicating if the flow is terminated or suspended or failed
     */
    protected String                    status;

    /**
     * Name of the Brillien node that has been delegated to pick up the flow by the node working on this Flow
     */
    protected String                    startedBy;

    /**
     * Name of the Brillien node that has been delegated to pick up the flow by the node working on this Flow
     */
    protected String                    delegatedTo;

    /**
     * The communication that activated the given Flow
     */
    protected BrillienCommunication activationMessage;

    {
        failureMessage = "";
        flowStateSpace = new HashMap<String, Object>();
    }

    /**
     * Getter method for the field flowName
     */
    public String getFlowName() {
        return flowName;
    }

    /**
     * Setter method for the field flowName
     */
    public void setFlowName(String flowName) {
        this.flowName = flowName;
    }

    /**
     * Getter method for the field flowState
     */
    public HashMap<String, Object> getFlowStateSpace() {
        return flowStateSpace;
    }

    /**
     * Setter method for the field flowState
     */
    public void setFlowStateSpace(HashMap<String, Object> flowStateSpace) {
        this.flowStateSpace = flowStateSpace;
    }

    /**
     * Getter method for the field startDate
     */
    public long getStartDate() {
        return startDate;
    }

    /**
     * Setter method for the field startDate
     */
    public void setStartDate(long startDate) {
        this.startDate = startDate;
    }

    /**
     * Getter method for the field timeout
     */
    public long getTimeout() {
        return timeout;
    }

    /**
     * Setter method for the field timeout
     */
    public void setTimeout(long timeout) {
        this.timeout = timeout;
    }

    /**
     * Getter method for the field message
     */
    public String getFailureMessage() {
        return failureMessage;
    }

    /**
     * Setter method for the field message
     */
    public void setFailureMessage(String failureMessage) {
        this.failureMessage = failureMessage;
    }

    /**
     * Getter method for the field status
     */
    public String getStatus() {
        return status;
    }

    /**
     * Setter method for the field status
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * Getter method for the field startedBy
     */
    public String getStartedBy() {
        return startedBy;
    }

    /**
     * Setter method for the field startedBy
     */
    public void setStartedBy(String startedBy) {
        this.startedBy = startedBy;
    }

    /**
     * Getter method for the field delegatedTo
     */
    public String getDelegatedTo() {
        return delegatedTo;
    }

    /**
     * Setter method for the field delegatedTo
     */
    public void setDelegatedTo(String delegatedTo) {
        this.delegatedTo = delegatedTo;
    }

    /**
     * Getter method for the field activationMessage
     */
    public BrillienCommunication getActivationMessage() {
        return activationMessage;
    }

    /**
     * Setter method for the field activationMessage
     */
    public void setActivationMessage(BrillienCommunication activationMessage) {
        this.activationMessage = activationMessage;
    }

    @Override
    public String toString() {
        return "IndispensableFlow{" +
                "flowName='" + flowName + '\'' +
                ", flowStateSpace=" + flowStateSpace +
                ", startDate=" + startDate +
                ", timeout=" + timeout +
                ", failureMessage='" + failureMessage + '\'' +
                ", status='" + status + '\'' +
                ", startedBy='" + startedBy + '\'' +
                ", delegatedTo='" + delegatedTo + '\'' +
                '}';
    }
}

